//控制层
app.controller("brandController", function($scope, $controller, brandService) {

	$controller('baseController', {
		$scope: $scope
	}); //继承

	//获取列表数据绑定到表单中
	$scope.findAll = function() {
		brandService.findAll().success(
			function(response) {
				$scope.list = response;
			}
		);
	}

	//分页
	//此方法被替代,不用了
	$scope.findPage = function(page, rows) {

		brandService.findPage(page, rows).success(
			function(response) {
				$scope.list = response.rows;
				$scope.paginationConf.totalItems = response.total; //更新总记录数
			}
		);
	}

	//查询实体
	$scope.findOne = function(id) {
		brandService.findOne(id).success(
			function(response) {
				$scope.entity = response;
			}
		);
	}

	//保存
	$scope.save = function() {
		//alert($scope.entity);
		/*	
			var methodName = "add";
			if($scope.entity.id != null) {
				methodName = "update";
			}*/

		var serviceObject;
		if($entity.id != null) { //如果有id,进行修改
			serviceObject = brandService.update();
		} else {
			serviceObject = brandService.add();
		}
		serviceObject.success(
			function(response) {
				if(response.success) {
					//重新查询
					$scope.reloadList();
				} else {
					alert(response.message);
				}
			}
		);
	}

	//批量删除
	$scope.dele = function() {
		//alert("delejjj");
		//获取复选框中的id
		brandService.dele($scope.selectIds).success(
			function(response) {
				if(response.success) {
					$scope.reloadList(); //刷新页面
					$scope.selectIds = [];
				}
			}
		);
	}

	//条件查询
	$scope.searchEntity = {};
	$scope.search = function(page, rows) {
		//alert("search");
		brandService.search(page,rows,$scope.searchEntity).success(
			function(response) {
				$scope.list = response.rows;
				$scope.paginationConf.totalItems = response.total; //更新总记录数
			}
		);
	}

});